home *** CD-ROM | disk | FTP | other *** search
/ Level 2005 Christmas (DVD) / Level_2005-XMAS_134_DVD_Knightshift.iso / Demos / Ski Racing 2006 / setup1.cab / DataCommonShadersDX9GhostSkinned.vsh < prev    next >
Encoding:
Text File  |  2005-11-03  |  2.9 KB  |  89 lines

  1. vs.1.1
  2.  
  3. ;Vertex packing
  4. dcl_position v0
  5. dcl_blendweight v1
  6. dcl_blendindices v2
  7. dcl_normal v3
  8. dcl_binormal v4
  9. dcl_tangent v5
  10. dcl_texcoord0 v7
  11.  
  12. ;Constant map from the NSF.  
  13. ;CM_Defined      SkinWorldViewProjTranspose  0    0
  14. ;CM_Constant     const_1_1_1_255             4    1   1.0,1.0,1.0,765.01
  15. ;CM_Constant     Half                        5    1   0.5,0.5,0.5,0.5                
  16. ;CM_Constant     Zero                        6    1   0.0,0.0,0.0,0.0
  17. ;CM_Defined      WorldViewTranspose            7    4
  18. ;CM_Defined      BoneMatrix3                 11   0   28
  19.  
  20. ;Determine the 4th weight.  We only pack 3, and this insures that the weights
  21. ;sum to 1.  We'll keep weights in r0.
  22. mov  r0.xyz, v1.xyz          ; r0.xyz = w0,w1,w2
  23. dp3  r0.w, v1.xyz, c4.xxxx   ; r0.w = w0 + w1 + w2
  24. add  r0.w, -r0.w, c4.x       ; r0.2 = 1 - (w0 + w1 + w2) = w3
  25.  
  26. ;Need to offset the values.  The indices are packed as floats from 0 to 1, but
  27. ;they are originally packed as bytes.  Since each bone matrix in this shader 
  28. ;takes 3 constant registers, we scale each float by 765.01 to make it equal
  29. ;the original byte value times 3.  The .01 insures that any floating point
  30. ;rounding does not bias our results incorrectly downward.
  31. mul  r1, v2.zyxw, c4.wwww    ; r1 = indices w/ offset (D3DCOLOR Version)
  32.  
  33. ;We now have the weights in r0 and the indices in r1.  We will move each 
  34. ;index into a0.x and blend a matrix together with the weights.  The registers
  35. ;r2, r3, and r4 will hold this final 3x4 matrix which we will use to transform
  36. ;points into world space as well as normals.  The points will end up in world
  37. ;space because each BoneMatrix3 represents a transform from bind pose skin
  38. ;space to bone space and the current transform from bone space to world space.
  39.  
  40. ;First bone
  41. mov  a0.x, r1.x
  42. mul  r2, r0.x, c[a0.x+0+11] ;8
  43. mul  r3, r0.x, c[a0.x+1+11]
  44. mul  r4, r0.x, c[a0.x+2+11]
  45.  
  46. ;Second bone
  47. mov  a0.x, r1.y
  48. mad  r2, r0.y, c[a0.x+0+11], r2
  49. mad  r3, r0.y, c[a0.x+1+11], r3
  50. mad  r4, r0.y, c[a0.x+2+11], r4
  51.  
  52. ;Third bone
  53. mov  a0.x, r1.z
  54. mad  r2, r0.z, c[a0.x+0+11], r2
  55. mad  r3, r0.z, c[a0.x+1+11], r3
  56. mad  r4, r0.z, c[a0.x+2+11], r4
  57.  
  58. ;Fourth bone
  59. mov  a0.x, r1.w
  60. mad  r2, r0.w, c[a0.x+0+11], r2
  61. mad  r3, r0.w, c[a0.x+1+11], r3
  62. mad  r4, r0.w, c[a0.x+2+11], r4
  63.  
  64. ;The vertex will now be deformed into world space with the blended matrix in
  65. ;r2, r3, and r4.
  66. dp4  r5.x, v0, r2
  67. dp4  r5.y, v0, r3
  68. dp4  r5.z, v0, r4
  69. mov  r5.w, c4.x
  70.  
  71. ;Transform normal to worldspace
  72. dp3  r11.x, v3, r2
  73. dp3  r11.y, v3, r3
  74. dp3  r11.z, v3, r4
  75. mov  r11.w, c6.x
  76.  
  77. ;Transform normal to viewspace
  78. m4x4 r10, r11, c6
  79.  
  80. ; Shouldn't be necessary to normalize normal since we hopefully got an orthogonal transform and unit source normals
  81.  
  82. ;Expand normal to texture coords (N * 0.5f + 0.5f)
  83. mad r10, r10, c5, c5
  84.  
  85. ;Calculate environment texture coords from worldspace normal
  86. mov oT0.xy, r10.xy
  87.  
  88. ;Transform position to clip space
  89. m4x4 oPos, r5, c0